package tictactoe.gameplay;

import java.util.Random;

import tictactoe.types.*;

/**
 *
 * @author Ryan Falls
 */
public class EasyCPUPlayer extends Player
{

    private Random rand;

    public EasyCPUPlayer(CellState symbol)
    {
	rand = new Random();
	if(symbol == CellState.NONE)
	{
	    //TODO: Throw exception
	}
	this.playerSymbol = symbol;
    }

     /**
     * Makes a move based on the current state of the tic-tac-toe board,
     * as determined by the cellStates array.
     * @param cellStates An array of CellState objects indicating the current
     * status of the board.
     * @return An int indicating the space where the move was made. Returns
     * -1 if it can't make a move.
     */
    @Override public int MakeMove(CellState[] cellStates)
    {
	return makeArbitraryMove(cellStates);
    }

    /**
     * Makes a move in an arbitrary cell.
     * @param cellStates Array of cellstates indicating the current status of the board.
     * @return The cell where the next move should be made.
     */
    protected int makeArbitraryMove(CellState[] cellStates)
    {
	int move;

	do
	{
	    move = rand.nextInt(9);
	}
	while(cellStates[move] != CellState.NONE);

	return move;
    }

    /**
     * Test to see if this is a computer or a human,
     * @return True if it is a computer, false if it is a human.
     */
    @Override
    public boolean isCPU()
    {
	return true;
    }
}
